import { accountStatusMap, allowLoginPcMap, insuranceTypeMap, sexMap, bloodTypeMap } from '@/config/dict'
import { byKeyGetItem, parseTime } from '@/utils'
import { validPhone, validIDCard, validAccount } from '@/utils/validate'
import { CustomStatus } from '@/components'

export const searchFormItem = (deptDropList) => {
  return [
    {
      type: 'input',
      key: 'keyword',
      label: '姓名/手机'
    },
    {
      type: 'select',
      key: 'deptId',
      label: '部门',
      options: deptDropList
    },
    {
      type: 'select',
      key: 'status',
      label: '状态',
      options: accountStatusMap
    }
  ]
}

export const tableColumn = (handleEdit, handleStart, handleDelete, handleResetPassword) => {
  return [
    {
      key: 'name',
      label: '姓名',
      minWidth: 100
    },
    {
      key: 'sex',
      label: '性别',
      minWidth: 80,
      render: (h, scope) => byKeyGetItem(sexMap, scope.row.sex).value
    },
    {
      key: 'birth',
      label: '生日',
      minWidth: 120,
      render: (h, scope) => parseTime(scope.row.birth, 'YYYY-MM-DD')
    },
    {
      key: 'phone',
      label: '手机',
      minWidth: 120
    },
    {
      key: 'account',
      label: '账号',
      minWidth: 120
    },
    {
      key: 'allowLoginPc',
      label: '登录后台',
      minWidth: 80,
      render: (h, scope) => <CustomStatus list={allowLoginPcMap} value={scope.row.allowLoginPc} />
    },
    {
      key: 'deptName',
      label: '部门',
      minWidth: 120
    },
    {
      key: 'postName',
      label: '岗位',
      minWidth: 100
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 80,
      render: (h, scope) => <CustomStatus list={accountStatusMap} value={scope.row.status} />
    },
    {
      type: 'button',
      label: '操作',
      list: [
        {
          name: '修改',
          authKey: 'd_4_2',
          click: handleEdit
        },
        {
          name: (scope) => scope.row.status === 1 ? '置为离职' : '置为在职',
          authKey: 'd_4_4',
          click: (id, row) => handleStart(id, row.status === 1 ? 2 : 1)
        },
        {
          name: '重置密码',
          authKey: 'd_4_5',
          confirm: '确定重置密码?',
          click: handleResetPassword
        },
        {
          name: '删除',
          authKey: 'd_4_3',
          confirm: '确定删除吗?',
          click: handleDelete
        }
      ]

    }
  ]
}

export const modalFormItem = (deptList, postList, contractTypeList, educationalList, rulesList, deviceList, handleIdNumberBlur, handleDeptChange) => {
  return [
    {
      type: 'input',
      key: 'name',
      label: '姓名',
      required: true,
      col: 8
    },
    {
      type: 'input',
      key: 'phone',
      label: '手机',
      rules: [
        { required: true, message: '手机号码不能为空' },
        { validator: validPhone, trigger: 'blur' }
      ],
      col: 8
    },
    {
      type: 'input',
      key: 'idNumber',
      label: '身份证号',
      slotListeners: {
        blur: handleIdNumberBlur
      },
      rules: [
        { required: true, message: '身份证号码不能为空' },
        { validator: validIDCard, trigger: 'blur' }
      ],
      col: 8
    },
    {
      type: 'input',
      key: 'account',
      label: '账号',
      rules: [
        { required: true, message: '账号不能为空' },
        { validator: validAccount, trigger: 'change' }
      ],
      col: 8
    },
    {
      type: 'select',
      key: 'sex',
      label: '性别',
      required: true,
      slotAttrs: {
        options: sexMap,
        disabled: true
      },
      col: 8
    },
    {
      type: 'date',
      key: 'birth',
      label: '生日',
      required: true,
      slotAttrs: {
        disabled: true
      },
      col: 8
    },
    // {
    //   type: 'input',
    //   key: 'brand',
    //   label: '年龄',
    //   required: true,
    //   col: 8
    // },
    {
      type: 'input',
      key: 'nativePlace',
      label: '籍贯',
      col: 8
    },
    {
      type: 'select',
      key: 'bloodType',
      label: '血型',
      slotAttrs: {
        options: bloodTypeMap
      },
      col: 8
    },
    {
      type: 'input',
      key: 'address',
      label: '家庭地址',
      slotAttrs: {
        style: { width: '97.8%' }
      },
      col: 24
    },
    {
      type: 'select',
      key: 'educationalLevel',
      label: '文化程度',
      slotAttrs: {
        options: educationalList
      },
      col: 8
    },
    {
      type: 'input',
      key: 'linkman',
      label: '紧急联系人',
      col: 8
    },
    {
      type: 'input',
      key: 'linkmanPhone',
      label: '紧急联系人手机',
      col: 8
    },
    {
      type: 'select',
      key: 'deptId',
      label: '部门',
      slotAttrs: {
        options: deptList
      },
      slotListeners: {
        change: handleDeptChange
      },
      col: 8
    },
    {
      type: 'select',
      key: 'postId',
      label: '岗位',
      slotAttrs: {
        options: postList
      },
      col: 8
    },
    {
      type: 'date',
      key: 'dutyDate',
      label: '入职日期',
      col: 8
    },
    {
      type: 'date',
      key: 'contractExpirationDate',
      label: '合同到期日期',
      col: 8
    },
    {
      type: 'select',
      key: 'contractType',
      label: '合同类型',
      slotAttrs: {
        options: contractTypeList
      },
      col: 8
    },
    {
      type: 'select',
      key: 'roleId',
      label: '权限角色',
      slotAttrs: {
        options: rulesList
      },
      col: 8
    },
    {
      type: 'select',
      key: 'insuranceTypeList',
      label: '保险类型',
      slotAttrs: {
        options: insuranceTypeMap,
        multiple: true,
        style: { width: '97.8%' }
      },
      col: 24
    },
    {
      type: 'select',
      key: 'deviceIdList',
      label: '绑定设备',
      // required: true,
      slotAttrs: {
        options: deviceList,
        multiple: true,
        style: { width: '97.8%' }
      },
      col: 24
    },
    {
      type: 'radio',
      key: 'allowLoginPc',
      label: '登录后台',
      required: true,
      slotAttrs: {
        options: allowLoginPcMap
      },
      col: 8
    },
    {
      type: 'radio',
      key: 'status',
      label: '状态',
      required: true,
      slotAttrs: {
        options: accountStatusMap
      },
      col: 8
    }
  ]
}

export const formButtons = (onSubmit, onReset) => {
  return {
    isDialog: true,
    submitName: '提交',
    resetName: '取消',
    submitCallback: values => onSubmit(values),
    resetCallback: () => onReset()
  }
}
